package logic

import (
	"context"
	"tiktok/model/mysql"
	"tiktok/tiktokrpc/internal/svc"
	"tiktok/tiktokrpc/tiktokrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type TikTokShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewTikTokShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TikTokShowLogic {
	return &TikTokShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *TikTokShowLogic) TikTokShow(in *tiktokrpc.TikTokShowRequest) (*tiktokrpc.TikTokShowResponse, error) {
	// todo: add your logic here and delete this line

	var tikTokContent mysql.TikTokContent

	mysql.DB.Debug().Where("id = ?", in.Id).Find(&tikTokContent)

	tikTokContent.Hot = tikTokContent.Hot + 1

	mysql.DB.Debug().Updates(&tikTokContent)

	return &tiktokrpc.TikTokShowResponse{
		Id:    int64(tikTokContent.ID),
		Title: tikTokContent.Title,
		Url:   tikTokContent.Url,
		Hot:   tikTokContent.Hot,
	}, nil
}
